package com.erp.freight.controller;

import com.erp.freight.domain.KjxStoreAccount;
import com.erp.freight.domain.bo.KjxStoreAccountBo;
import com.erp.freight.domain.vo.KjxStoreAccountVo;
import com.erp.freight.service.IKjxStoreAccountService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 熊迪仓库账号
 *
 * @author erp
 * @date 2024-04-07
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/kjx/storeAccount")
public class KjxStoreAccountController extends BaseController {

    private final IKjxStoreAccountService iKjxStoreAccountService;

    /**
     * 根据账号查询熊迪用户信息
     */
    @GetMapping("/getInfoByAccount")
    public KjxStoreAccount getInfoByAccount(String account) {
        return iKjxStoreAccountService.getInfoByAccount(account);
    }

    /**
     * 查询熊迪仓库账号列表
     */
    @GetMapping("/list")
    public TableDataInfo<KjxStoreAccountVo> list(KjxStoreAccountBo bo, PageQuery pageQuery) {
        return iKjxStoreAccountService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出熊迪仓库账号列表
     */
    @Log(title = "熊迪仓库账号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(KjxStoreAccountBo bo, HttpServletResponse response) {
        List<KjxStoreAccountVo> list = iKjxStoreAccountService.queryList(bo);
    }

    /**
     * 获取熊迪仓库账号详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<KjxStoreAccountVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iKjxStoreAccountService.queryById(id));
    }

    /**
     * 新增熊迪仓库账号
     */
    @Log(title = "熊迪仓库账号", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@RequestBody KjxStoreAccountBo bo) {
        return toAjax(iKjxStoreAccountService.insertByBo(bo));
    }

    /**
     * 修改熊迪仓库账号
     */
    @Log(title = "熊迪仓库账号", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@RequestBody KjxStoreAccountBo bo) {
        return toAjax(iKjxStoreAccountService.updateByBo(bo));
    }

    /**
     * 删除熊迪仓库账号
     *
     * @param ids 主键串
     */
    @Log(title = "熊迪仓库账号", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iKjxStoreAccountService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
